//
//  VisitorView.swift
//  dwdWb
//
//  Created by Dengdwd on 15/10/6.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit

protocol VisitorViewDelegate:NSObjectProtocol {

    func visitorLogin()
    func visitorRegister()

}

class VisitorView: UIView {
    weak var visitorDelegate : VisitorViewDelegate?
    
    @IBOutlet weak var smallIcon: UIImageView!

    @IBOutlet weak var icon: UIImageView!
    
    @IBOutlet weak var descLabel: UILabel!
    
    func setUpVisitorUI (imageName:String, content:String, isHome:Bool = false) {
    icon.image = UIImage(named: imageName)
    descLabel.text = content
    smallIcon.hidden = !isHome
        if isHome {
           startAnimation()
        }
    }
    private func startAnimation () {
    let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.repeatCount = MAXFLOAT
        anim.duration = 8
        anim.toValue = 2 * M_PI
        anim.removedOnCompletion = false
        smallIcon.layer.addAnimation(anim, forKey: nil)
    }
    
    @IBAction func login() {
        visitorDelegate?.visitorLogin()
    }
    @IBAction func register() {
        visitorDelegate?.visitorRegister()
    }
}
